<template>
	<view class="settings">
		<view class="setting">
			<view class="list-box">
				<view class="list" @click="goPage('/pages/users/cooperation/cooperation')">
					<view class="list-left">
						<text class="iconfont icon-hezuo"></text>
						<text>商务合作</text>
					</view>
					<view class="list-right">
						<text>查看联系方式</text>
						<text class="iconfont icon-dayu"></text>
					</view>
				</view>
				<!-- #ifdef APP-PLUS -->
				<view class="list">
					<view class="list-left">
						<text class="iconfont icon-shouquan"></text>
						<text>淘宝授权</text>
					</view>
					<view class="list-right">
						<text v-if="isAuthorization">已授权</text>
						<text v-else @click="login">去授权</text>
						<text class="iconfont icon-dayu"></text>
					</view>
				</view>
				<!-- #endif -->
				<view class="list" @click="goPage('/pages/public/agreement/agreement?name=隐私协议&keyword=privacy_rule')">
					<view class="list-left">
						<text class="iconfont icon-xieyi"></text>
						<text>隐私协议</text>
					</view>
					<view class="list-right">
						<text>立即查看</text>
						<text class="iconfont icon-dayu"></text>
					</view>
				</view>
				<view class="list" v-if="isLogin" @click="goPage('/pages/users/cancellation/cancellation')">
					<view class="list-left">
						<text class="iconfont icon-cancellation"></text>
						<text>注销账号</text>
					</view>
					<view class="list-right">
						<text>谨慎操作</text>
						<text class="iconfont icon-dayu"></text>
					</view>
				</view>
				<!-- #ifdef APP-PLUS -->
				<view class="list">
					<view class="list-left">
						<text class="iconfont icon-about"></text>
						<text>关于转客盟</text>
					</view>
					<view class="list-right" @click="onAPPUpdate()">
						<text>当前版本{{version}}</text>
						<text class="iconfont icon-dayu"></text>
					</view>
				</view>
				<!-- #endif -->
			</view>
		</view>
		<view class="btns" :class="$isPC ? 'IsPC':''">
			<view class="btn" v-if="isLogin" @click="clearSign()">
				<text>退出登录</text>
			</view>
			<view class="btn" v-else @click="goPage('/pages/entrance/login/login')">
				<text>立即登录</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	// #ifdef APP-PLUS
	import APPUpdate, {
		getCurrentNo
	} from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';
	import {
		TAOBAOISLOGIN,
		TAOBAOLOGIN
	} from "@/utils/duomai.js"
	// #endif
	export default {
		name: "settings",
		data() {
			return {
				version: "", // 版本号
				isAuthorization:false,
			}
		},
		computed: {
			...mapState(['isLogin']),
		},
		//第一次加载
		async onLoad(e) {
			// #ifdef APP-PLUS
			getCurrentNo(res => {
				// 进页面获取当前APP版本号（用于页面显示）
				this.version = res.versionName;
			});
			this.isAuthorization = await TAOBAOISLOGIN();
			// #endif
		},
		methods: {
			...mapMutations(['setUserInfo_mutation']),
			async login(){
				await TAOBAOLOGIN();
				this.isAuthorization = await TAOBAOISLOGIN();
			},
			// 检查APP是否有新版本
			onAPPUpdate() {
				// true 没有新版本的时候有提示，默认：false
				APPUpdate(true);
			},
			goPage(url) {
				uni.navigateTo({
					url: url
				})
			},
			//退出登录
			clearSign() {
				let userInfo = {
					avatar: "",
					create_time: 0,
					currency: 0,
					id: "",
					invitation_code: "",
					invitation_total: 0,
					isLogin: false,
					last_login_time: 0,
					parent_id: 0,
					phone: "",
					power: 0,
					reward_end_time: 0,
					reward_lord: 0,
					temporary_power: 0,
					username: "",
				};
				uni.removeStorageSync('oauth_token');
				this.setUserInfo_mutation(userInfo)
				uni.navigateTo({
					url: '/pages/entrance/login/login'
				})
			}
		}
	}
</script>

<style scoped lang="less" src="./settings.less">
</style>
